package com.ftg.learn.loadbalance;

import java.util.Arrays;
import java.util.List;

/**
 * @author 布衣
 */
public class HashIpQuery {

    public RedisInstance get(List<RedisInstance> list, String ipAddr) {
        return list.get(ipAddr.hashCode() &( list.size()-1));
    }

    public static void main(String[] args) {

        HashIpQuery t = new HashIpQuery();
        List<RedisInstance> list = Arrays.asList(new RedisInstance("127.0.0.1",6380),new RedisInstance("127.0.0.1",6381),new RedisInstance("127.0.0.1",6382));
        for (int i = 0; i < 100; i++) {
            System.out.println(t.get(list, "192.168.21.221")+"==>ip redis 从服务器");
        }

    }

}
